<?php include('includes/before_html.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

        <meta http-equiv="content-type" content="text/html; charset=utf-8" />

        <meta name="description" content="" />

        <meta name="keywords" content="" />

        <meta name="author" content="" />

        <?php include('includes/head.php'); ?>

        <title><?php echo $heading ?></title>

    </head>

    <body>

        <div id="wrapper">

            <?php include('includes/header.php'); ?>

            <?php include('includes/nav.php'); ?>

            <div id="content">
                <?php
                $db = mysql_connect(db_server, $db_user, $db_password);
                mysql_select_db($db_dbname);
                $myid = $_COOKIE['ruid'];
                if (isset($_GET['rid'])) {
                    $hisid = $_GET['rid'];
                    if ($_GET['a']) {
                        $status = 'Accepted';
                        $result = mysql_query("UPDATE Friends SET Status='$status' WHERE Person1=" . $_GET['rid'] . " AND Person2=" . $_COOKIE['ruid']);
                        $add_new_entry = mysql_query("INSERT INTO Friends (Person1,Person2,Status) VALUES (" . $_COOKIE['ruid'] . "," . $_GET['rid'] . ",'$status') ON DUPLICATE KEY UPDATE Status='$status'");
                    } else {
                        $status = 'Ignored';
                        $result = mysql_query("DELETE FROM Friends WHERE (Person1=$myid AND Person2=$hisid) OR (Person1=$hisid AND Person2=$myid)");
                        $add_new_entry = 1;
                    }
                    if ($result && $add_new_entry) {
                        if ($_GET['f'])
                            echo "You have unfriended " . getName ($_GET['rid']);
                        else
                            echo "Friend request from " .  getName ($_GET['rid']) . " has been $status";
                    } else {
                        echo "Error processing request.";
                    }
                }
                ?>

            </div> <!-- end #content -->

            <?php include('includes/sidebar.php'); ?>

            <?php include('includes/footer.php'); ?>

        </div> <!-- End #wrapper -->

    </body>

</html>